package JET;

import JET.Centers.ControlCenter;
import JET.Centers.Graphics.GUICenter;
import JET.Frames.MainFrame;
import JET.graphics.jogl.GLHelper;
import JET.mygui.MultiSplitPane;
import javax.swing.JFrame;
import javax.swing.UIManager;
import java.awt.BorderLayout;
import java.io.File;
import java.io.FileInputStream;

/**
 *
 * @author 057Ry
 */
public class Main implements Constants
{
    /**
     * @param args the command line arguments
     */
    public static void main(String[] args)
    {
        // At the begginin there was a Word ...
        // Najpierw decydujemy o wygladzie aplikacji, specyfing Look & Feel
        try { UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName()); } catch (Exception ex) { ex.printStackTrace(); }

        // First of all we need to have control over all stuff - "(...) and one to rule them all (...)"
        final ControlCenter CC = ControlCenter.getInstance();
        
        // Now we can build visualization for Engine and tools
        MainFrame mainFrame = new MainFrame();
        mainFrame.setLocationRelativeTo( null );
        mainFrame.setExtendedState(mainFrame.getExtendedState() | JFrame.MAXIMIZED_BOTH);
        mainFrame.setVisible(true);

        // Start building gui elements ...
        GUICenter guic = new GUICenter();
        guic.setRootFrame(mainFrame);
        CC.setGUIC(guic);

        MultiSplitPane msp=null;
        File layoutFile = new File("guiLayout.xml");
        FileInputStream is=null;
        if (layoutFile.exists())
            try {
                msp = guic.builGuiSctructure((is= new FileInputStream(layoutFile)), CC);
            } catch(Exception ex) {ex.printStackTrace();}
            finally {
                try {if (is!=null)is.close();}catch(Exception e) {e.printStackTrace();}
            }
        else
            msp = guic.builGuiSctructure(Object.class.getResourceAsStream("/JET/gui.xml"), CC);

        if (msp==null) throw new RuntimeException("main(), msp is null !");
        mainFrame.guiRootPanel.add(msp, BorderLayout.CENTER);
        mainFrame.guiRootPanel.updateUI();
        
        // Creation of dialog frames
        CC.GUIC.initDialogs();

        assert CC!=null;

        /*
        Scene scene = new Scene();
        scene.getEngine().setMainBound(SCENE_START_WIDTH, SCENE_START_HEIGHT);
        CC.addScene(scene, "A");
        scene.SC.injectSceneIntoJSEngine(scene.getEngine());
        CC.GUIC.openSceneTab("A");
        */

        GLHelper.initData();
    }
}